package dao.impl;
import dao.UserDao;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import pojo.User;

import java.io.InputStream;
import java.util.List;

public class UserDaoImpl implements UserDao {
    @Override
    public List<User> findAll() {
        //引入mybatis配置文件
        String resource = "mybatis-config.xml";
        //加载配置文件
        InputStream inputStream = UserDaoImpl.class.getClassLoader().getResourceAsStream(resource);
        //创建一个会话工厂
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        //创建一个会话
        org.apache.ibatis.session.SqlSession sqlSession = sqlSessionFactory.openSession();
        //执行查询
        List<User>users = sqlSession.getMapper(UserDao.class).findAll();
        return users;

    }
}